﻿using AiXiu.BLL;
using AiXiu.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AiXiu.WebSite.Handler
{
    /// <summary>
    /// VideoLikeHandler 的摘要说明
    /// </summary>
    public class VideoLikeHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            OperResult operResult = new OperResult();
            // 接收参数
            string videoId = context.Request.Form["videoId"];
            string userIdStr = context.Request.Form["userId"];
            string action = context.Request.Form["action"];
            if (!string.IsNullOrWhiteSpace(videoId) &&
                !string.IsNullOrWhiteSpace(userIdStr) &&
                !string.IsNullOrWhiteSpace(action))
            {
                // 执行操作
                int userId = int.Parse(userIdStr);
                LikeManager likeManager = new LikeManager();
                switch (action)
                {
                    case "add":
                        operResult = likeManager.AddLike(videoId, userId);
                        break;
                    case "remove":
                        operResult = likeManager.RemoveLike(videoId, userId);
                        break;
                    default:
                        break;
                }
            }

            // 输出结果
            var data = JsonConvert.SerializeObject(operResult);
            context.Response.Write(data);
            // 输出结果
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}